package com.meituan.catering.management.shop.biz.model.converter;

import com.meituan.catering.management.common.model.biz.PageBO;
import com.meituan.catering.management.shop.api.http.model.response.ShopDetailHttpResponse;
import com.meituan.catering.management.shop.api.http.model.response.ShopPageHttpResponse;
import com.meituan.catering.management.shop.biz.model.ShopBO;

import java.util.stream.Collectors;

/**
 * 从其他数据模型向门店Http模型的转换器
 */
public abstract class ShopHttpVOConverter {

    public static ShopDetailHttpResponse fromBO(ShopBO shopBO) {
        if (shopBO == null) {
            return null;
        } else {
            ShopDetailHttpResponse httpResponse = new ShopDetailHttpResponse();
            httpResponse.setId(shopBO.getId());
            httpResponse.setTenantId(shopBO.getTenantId());
            httpResponse.getAuditing().setCreatedBy(shopBO.getAuditing().getCreatedBy());
            httpResponse.getAuditing().setCreatedAt(shopBO.getAuditing().getCreatedAt());
            httpResponse.getAuditing().setLastModifiedBy(shopBO.getAuditing().getLastModifiedBy());
            httpResponse.getAuditing().setLastModifiedAt(shopBO.getAuditing().getLastModifiedAt());

            httpResponse.setBusinessNo(shopBO.getBusinessNo());
            httpResponse.setName(shopBO.getName());
            httpResponse.setBusinessType(shopBO.getBusinessType());
            httpResponse.getContact().setTelephone(shopBO.getContact().getTelephone());
            httpResponse.getContact().setCellphone(shopBO.getContact().getCellphone());
            httpResponse.getContact().setName(shopBO.getContact().getName());
            httpResponse.getContact().setAddress(shopBO.getContact().getAddress());
            httpResponse.getOpeningHours().setOpenTime(shopBO.getOpenTime());
            httpResponse.getOpeningHours().setCloseTime(shopBO.getCloseTime());
            httpResponse.setManagementType(shopBO.getManagementType());
            httpResponse.setBusinessArea(shopBO.getBusinessArea());
            httpResponse.setComment(shopBO.getComment());
            httpResponse.setEnabled(shopBO.getEnabled());
            httpResponse.setVersion(shopBO.getVersion());
            return httpResponse;
        }
    }


    public static ShopPageHttpResponse fromPageBO(PageBO<ShopBO> shopPageBO) {
        if (shopPageBO == null) {
            return null;
        } else {
            ShopPageHttpResponse httpResponse = new ShopPageHttpResponse();
            httpResponse.setPageIndex(shopPageBO.getPageIndex());
            httpResponse.setPageSize(shopPageBO.getPageSize());
            httpResponse.setTotalCount(shopPageBO.getTotalCount());
            httpResponse.setTotalPageCount(shopPageBO.getTotalPageCount());
            httpResponse.getRecords().addAll(shopPageBO.getRecords().stream().map(ShopHttpVOConverter::fromPageBORecord).collect(Collectors.toList()));
            return httpResponse;
        }
    }

    public static ShopPageHttpResponse.Record fromPageBORecord(ShopBO shopBO) {
        if (shopBO == null) {
            return null;
        } else {
            ShopPageHttpResponse.Record record = new ShopPageHttpResponse.Record();
            record.setId(shopBO.getId());
            record.setTenantId(shopBO.getTenantId());
            record.getAuditing().setCreatedBy(shopBO.getAuditing().getCreatedBy());
            record.getAuditing().setCreatedAt(shopBO.getAuditing().getCreatedAt());
            record.getAuditing().setLastModifiedBy(shopBO.getAuditing().getLastModifiedBy());
            record.getAuditing().setLastModifiedAt(shopBO.getAuditing().getLastModifiedAt());
            record.setBusinessNo(shopBO.getBusinessNo());
            record.setName(shopBO.getName());
            record.setBusinessType(shopBO.getBusinessType());
            record.getContact().setTelephone(shopBO.getContact().getTelephone());
            record.getContact().setCellphone(shopBO.getContact().getCellphone());
            record.getContact().setName(shopBO.getContact().getName());
            record.getContact().setAddress(shopBO.getContact().getAddress());


            record.getOpeningHours().setOpenTime(shopBO.getOpenTime());
            record.getOpeningHours().setCloseTime(shopBO.getCloseTime());
            record.setManagementType(shopBO.getManagementType());

            record.setBusinessArea(shopBO.getBusinessArea());
            record.setComment(shopBO.getComment());
            record.setEnabled(shopBO.getEnabled());
            record.setVersion(shopBO.getVersion());
            return record;
        }
    }

}
